<?php
//error_reporting(E_ERROR);
error_reporting(E_ALL|E_NOTICE);
ini_set('display_errors', 'on');

define('FROM_INDEX', true);
define('ROOT_PATH', dirname(__FILE__).'/');

require_once ROOT_PATH.'include/lib/load_setting.php';
load_setting('config_global');
@header('Content-Type: text/html; charset='.CHARSET);

require_once ROOT_PATH.'mobiapi/conf/config_servlet.php';
require_once ROOT_PATH.'include/function/global.func.php';
require_once ROOT_PATH.'include/lib/image.func.php';
require_once ROOT_PATH.'include/logic/image.logic.php';
require_once ROOT_PATH.'include/logic/user.logic.php';

require_once ROOT_PATH.'include/cache/class_cache_factory.php';
require_once ROOT_PATH.'mobiapi/include/function/servlet.func.php';
require_once ROOT_PATH.'service/story.service.php';

require_once ROOT_PATH.'lib/baidu_bcs/bcs.func.php';

/*
$image_str = file_get_contents(ROOT_PATH.'lib/baidu_bcs/sample/test.png');
//var_dump("---001---".$image_str);

$image_str = base64_encode($image_str);
//var_dump("---002---".$image_str);

//$pkg_name = 'user-1-nikm';
$img_name = '/story/1/1-'.time().'.jpg';

var_dump(delete_from_bcs('/story/1/1-1380425871.jpg'));
var_dump(save_to_bcs($img_name, $image_str));
*/

//image_resize('http://bcs.duapp.com/oye-bucket/user%2F47%2F-1380426555.jpg', 'data/tmp.jpg', 100, 100);

//$img_str = get_resized_str('http://bcs.duapp.com/oye-bucket/user%2F47%2F-1380426555.jpg', 100, 100);
//$img_name = '/user/47/test.jpg';

//save_to_bcs_from_file($img_name, $img_str);

//echo base64_encode(file_get_contents('data/test.png'));

//var_dump(generate_password('123123', array('email'=>'Robin@163.com', 'time'=>'1381331399')));

//for ($i=1; $i<=100; $i++)
//{
//	clear_bcs_dir("/story/$i/");
	//for ($j=1; $j<28; $j++)
	//{
	//	clear_bcs_dir("/story/$i/2013-10-$j/");
	//}
//}

//clear_bcs_dir("/story/65/");
   
   // cacheFactory::getInstance()->set('mykey2', 'Just for test 2', 2332800);
   // echo cacheFactory::getInstance()->get('mykey2');
   
   //$request = array('grant_type'=>'client_credentials', 'client_id'=>'DGhyV4ewxIR5IwrdHzNUeag4', 'client_secret'=>'oC92hhZ356XtonbKiQl5LAdN1NTu41Gg');
   //$result = post_request('https://openapi.baidu.com/oauth/2.0/token', $request);
   //var_dump($result);
   //var_dump(json_decode($result));
   
//$token = '3.c0a7b17520fa31cc248435a86de6b67b.2592000.1389108057.282335-1341805';
//$result = create_video_job('story/userVideo/2013-12/8093.mp4', 'media/userVideo/2013-12/testnikm.mp4', $token);
//var_dump(parse_json($result));

$url = 'http://bcs.duapp.com/oye-bucket/story/userVideo/2013-12/8093.mp4';

$input_name = substr($url, stripos($url, 'oye-bucket')+11);
$output_name = 'media/userVideo/'.date('Y-m').'/'.substr($url, strripos($url, '/')+1);

var_dump($input_name, $output_name);

$result = trans_video($input_name, $output_name);

var_dump($result);